import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store';

Vue.use(VueRouter)

const routes = [
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/Login/Login')
    },
    {
        path: '/',
        name: 'indexpage',
        component: () => import('../views/IndexPage/IndexPage'),
        children: [
            {
                path: "/workbench",
                name: "工作台",
                component: () => import('../views/IndexPage/workbench/index.vue'),
            },
            {
                path: "/commodity",
                component: () => import('../views/IndexPage/commodity'),
                children: [
                    {
                        path: "/commodity/admin",
                        name: "商品管理",
                        component: () => import('../views/IndexPage/commodity/admin/index.vue'),
                    },
                    {
                        path: "/commodity/class",
                        name: "商品分类"
                    },
                    {
                        path: "/commodity/specs",
                        name: "商品规格"
                    },
                    {
                        path: "/commodity/evaluate",
                        name: "商品评价"
                    }
                ]
            },
            {
                path: "/evaluate",
                children: [
                    {
                        path: "/evaluate/kill",
                        children: [
                            {
                                path: "/evaluate/kill/config",
                                name: "秒杀配置"
                            },
                            {
                                path: "/evaluate/kill/commodity",
                                name: "秒杀商品"
                            }
                        ]
                    },
                    {
                        path: "/evaluate/bargaining",
                        children: [
                            {
                                path: "/evaluate/bargaining/commodity",
                                name: "砍价商品"
                            },
                            {
                                path: "/evaluate/bargaining/list",
                                name: "砍价列表"
                            }
                        ]
                    },
                    {
                        path: "/evaluate/live",
                        children: [
                            {
                                path: "/evaluate/live/list",
                                name: "直播列表"
                            },
                            {
                                path: "/evaluate/live/create",
                                name: "创建直播"
                            }
                        ]
                    },
                    {
                        path: "/evaluate/groupwork",
                        children: [
                            {
                                path: "/evaluate/groupwork/commodity",
                                name: "拼团商品"
                            },
                            {
                                path: "/evaluate/groupwork/list",
                                name: "拼团列表"
                            }
                        ]
                    }
                ]
            },
            {
                path: "/order",
                component: () => import('../views/IndexPage/order'),
                children: [
                    {
                        path: "/order/admin",
                        name: "订单管理",
                        component: () => import('../views/IndexPage/order/admin/index.vue')
                    },
                    {
                        path: "/order/generalization",
                        name: "订单概括"
                    },
                    {
                        path: "/order/evaluate",
                        name: "评价管理"
                    },
                    {
                        path: "/order/delivery",
                        name: "订单派送",
                        // component: () => import('../views/Express/index.vue')
                    }
                ]
            },
            {
                path: "/chief",
                children: [
                    {
                        path: "/chief/admin",
                        name: "团长管理"
                    },
                    {
                        path: "/chief/examine",
                        name: "团长审核"
                    },
                    {
                        path: "/chief/grade",
                        name: "团长等级"
                    },
                    {
                        path: "/chief/config",
                        name: "设置"
                    },
                    {
                        path: "/chief/route",
                        name: "路线"
                    }
                ]
            },
            {
                path: "/store",
                component: () => import('../views/IndexPage/store'),
                children: [
                    {
                        path: "/store/config",
                        name: "配置",
                        component: () => import('../views/IndexPage/store/config/index.vue')
                    },
                    {
                        path: "/store/store",
                        name: "门店"
                    },
                    {
                        path: "/store/commodity",
                        name: "商品"
                    },
                    {
                        path: "/store/order",
                        name: "订单",
                        component: () => import('../views/IndexPage/store/order/index.vue'),
                    },
                    {
                        path: "/store/withdrawal",
                        name: "提现"
                    },
                    {
                        path: "/store/pay",
                        name: "到店付款"
                    }
                ]
            },
            {
                path: "/warehouse",
                component: () => import('../views/IndexPage/warehouse'),
                children: [
                    {
                        path: "/warehouse/admin",
                        name: "仓库管理"
                    },
                    {
                        path: "/warehouse/quarters",
                        name: "配送小区"
                    },
                    {
                        path: "/warehouse/warehousing",
                        name: "入库管理"
                    },
                    {
                        path: "/warehouse/query",
                        name: "入库查询"
                    },
                    {
                        path: "/warehouse/delivery",
                        name: "出库管理"
                    },
                    {
                        path: "/warehouse/read",
                        name: "出库查询"
                    },
                    {
                        path: "/warehouse/inventory",
                        name: "盘点管理"
                    },
                    {
                        path: "/warehouse/stock",
                        name: "现有库存",
                        component: () => import('../views/IndexPage/warehouse/stock/index.vue'),
                    }
                ]
            },
            {
                path: "/distribution",
                component:()=>import('../views/IndexPage/distribution'),
                children: [
                    {
                        path: "/distribution/svip",
                        name: "超级会员",
                        component:()=>import('../views/IndexPage/distribution/svip/index.vue')
                    },
                    {
                        path: "/distribution/proxy",
                        name: "代理商",
                        component:()=>import('../views/IndexPage/distribution/proxy/index.vue')
                    },
                    {
                        path: "/distribution/payinf",
                        name: "佣金记录",
                        component:()=>import('../views/IndexPage/distribution/payinf/index.vue')
                    },
                    {
                        path: "/distribution/set",
                        name: "设置",
                        component:()=>import('../views/IndexPage/distribution/set/index.vue')
                    }
                ]
            },
            {
                path: "/applets",
                component:()=>import('../views/IndexPage/applets'),
                children: [
                    {
                        path: "/applets/pay",
                        name: "支付",
                        component:()=>import('../views/IndexPage/applets/pay/index.vue'),
                    }
                ]
            },
            {
                path: "/auth",
                children: [
                    {
                        path: "/auth/user",
                        name: "员工管理"
                    },
                    {
                        path: "/auth/pos",
                        name: "角色管理"
                    },
                    {
                        path: "/auth/server",
                        name: "客服管理"
                    }
                ]
            }
        ]
    },
    {
        path: '/express',
        name: 'Express',
        component: () => import('../views/Express/index.vue')
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    const url = ['/', '/login',"/order/delivery"];
    if (!url.some(item => item === to.path)) {
        if (store.state.authPath.some(item => item === to.path)) {
            next();
        }
    } else next();
    if(to.fullPath==="/order/delivery"){
        next('/express')
    }else{
        next()
    }
})

export default router;
